﻿<!DOCTYPE html>
<html>
<head>
	  <meta charset="utf-8">
	  <title></title>
	  <meta name="renderer" content="webkit">
	  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	  <link rel="stylesheet" href="../layui/css/layui.css"  media="all">
</head>
<body>

	<div class="layui-fluid">
      <div class="layui-form">
        <div class="layui-inline">
          <button class="layui-btn layui-btn-primary" id="importExcel">导出excel</button>
        </div>
        <div class="layui-inline">
          日期选择：
        </div>
        <div class="layui-inline">
          <input type="text" class="layui-input" id="date1" style="width:300px;">
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">状态筛选：</label>
              <div class="layui-input-block">
                <select name="interest" lay-filter="level" id="level">
                  <option value="all">全部</option>
                  <option value="3">待定</option>
                  <option value="1">转单</option>
                  <option value="0">不合格</option>
                  <option value="2">已读</option>
                </select>
              </div>
        </div>
        <div class="layui-inline" id="yunweiBox">
            
        </div>
        <div class="layui-inline" >
          电话搜索：
        </div>
        <div class="layui-inline"><input id="mobileSearch" type="text" lay-filter="mobileSearch" class="layui-input"></div>
        
      </div>
      <div class="layui-block">
  		  <table id="demo" lay-filter="test"></table>
      </div>
      
	</div>      
</body>
<script src="../layui/layui.all.js"></script>
<script type="text/javascript" src="../../disanfanglogin/vendor/jquery/jquery-3.2.1.min.js"></script>
<script type="text/javascript" src="../js/linxi.js?type=9"></script>
<script type="text/javascript">
	$(document).ready(function(){

    linxi.loginYanZheng(function(data){


      var userInfo = data.data

      var userId = userInfo.userId 

      var titleId = userInfo.titleId

      var form = linxi.form

      var table = linxi.table

      var element = layui.element

      var layer = layui.layer

      if(userInfo.user_root.customer_monitoring==0){
          layer.msg('非法闯入')
          return;
      }

      if(titleId=='admin' || titleId=='group_leader' || titleId=='QC'){

        userId = 'all'

        $.get('../api/api.php?type=getYunWei',function(data){
                  
            var data = JSON.parse(data).data

            $yuweiHtmlSelect =  `<label class="layui-form-label">负责人：</label>
                                 <div class="layui-input-block">
                                  <select name="interest" lay-filter="yunwei" id="yunwei">
                                  <option value = "all">全部</option>`

            for(var i = 0 ;  i < data.length ; i++){

                $yuweiHtmlSelect+=`<option value = "${data[i]['userId']}">${data[i]['name']}</option>`
            }

            $yuweiHtmlSelect+=`</select></div>`

            $('#yunweiBox').html($yuweiHtmlSelect)

            form.render('select')

            form.on('select(yunwei)', function(data){

              // console.log(getlayerVals())

              table.reload('demo',{
                url:'../api/api.php' + linxi.createUrlParse(getlayerVals())
              })

            });

        })

        


      }


      linxi.createTable(

        {'type':'getKeFunFenPeiTable','starDate':linxi.starDate,'endDate':linxi.endDate,'userId':userId,'status':$('#level').val(),'mobile':'all'}
        ,'#demo'
        ,[ //表头
             
             {field: '', title: '序号',  type: 'numbers', fixed: 'left'}
            ,{field: 'customerId', title: 'ID',  fixed: 'left'}
            ,{field: 'updatetime', title: '分配日期',  sort: true, fixed: 'left'}
            ,{field: 'qudao', title: '渠道', }
            ,{field: 'mobile', title: '手机号'}
            ,{field: 'name', title: '负责人'}
            ,{field: '', title: '客资状态',templet:function(d){return d.customer_status==3?'待定':d.customer_status==1?'转单':d.customer_status==2?'已读':'不合格'}}
          ]
        ,true
      )

      linxi.laydate('#date1',function(value, date, endDate){

            var parmsObj=getlayerVals()
            parmsObj['starDate'] =value.split(' - ')[0]
            parmsObj['endDate'] = value.split(' - ')[1]

            table.reload('demo', {
              url: '../api/api.php' + linxi.createUrlParse(parmsObj)
            });
      })  //创建时间选择框


      linxi.table.on('rowDouble(test)',function(obj){
        linxi.showRemark(obj)
      })

      $('#importExcel').click(function(e){


          var index = linxi.layer.load(0, {shade: false})



          $.get('../api/api.php' + linxi.createUrlParse(getlayerVals()),function(data){


                      var res = JSON.parse(data)

                      console.log(res)


                      for(var i = 0 ; i < res.count ; i++){

                        if(res.data[i]['customer_status']==0){
                          res.data[i]['customer_status']='不合格'
                        }else if(res.data[i]['customer_status']==1){
                          res.data[i]['customer_status']='转单'
                        }else if(res.data[i]['customer_status']==2){
                          res.data[i]['customer_status']='已读'
                        }else if(res.data[i]['customer_status']==3){
                          res.data[i]['customer_status']='待定'
                        }

                        $.ajax(
                          { 
                            url:'../api/api.php?type=getbyRemark&customer=' + res.data[i].customerId,
                            async:false,
                            success: function(data){
                              data = JSON.parse(data)
                              var list = data.data.list
                              res.data[i]['followUserName'] = list[0]['followUserName']
                              res.data[i]['remark'] = list[0]['remark']
                              for(var j = 0 ; j < list.length ; j++){

                                if(list[j]['callInstanceId']!==null){
                                  res.data[i]['callInstanceId'] = list[j]['callInstanceId']
                                  res.data[i]['luyinOssUrl'] = list[j]['luyinOssUrl']
                                  break
                                }
                              }  
                             
                            }
                          }
                        );
                      }

    
                      res['data'] = JSON.stringify(res['data'])
                      res['type']='importExcel'
                      res['tableName']='林西客资'
                      res['fields'] = [{field:'customerId',title:'ID'},{field:'updatetime',title:'最后更新日期'},{field:'mobile',title:'手机号'},{field:'contactName',title:'客户姓名'},{field:'qudao',title:'渠道'},{field:'name',title:'负责人'},{field:'remark',title:'备注'},{field:'followUserName',title:'客服姓名'},{field:'customer_status',title:'客资状态'},{field:'callInstanceId',title:'通话ID'},{field:'luyinOssUrl',title:'录音链接'},{field:'Reasons_for_disqualification',title:'备注'}]
                      
                      $.post('../api/api.php',res,function(data){
                          
                          linxi.download_file(data)

                          linxi.layer.close(index)
                      })


          })
      })

        

      form.on('select(level)', function(data){

        console.log(getlayerVals())

        table.reload('demo',{
          url:'../api/api.php' + linxi.createUrlParse(getlayerVals())
        })

      });


      // form.on('change(mobileSearch)',function(data){
      //   console.log(data)
      // })

      $("#mobileSearch").keyup(function(e){
        
        var mobile = $(e.currentTarget).val()
        var parmsObj = getlayerVals()
        if(mobile.length==11){
          console.log(mobile)
          
          parmsObj['mobile'] = mobile
          table.reload('demo',{
            url:'../api/api.php' + linxi.createUrlParse(parmsObj)
          })
        }else if (mobile.length==0){
          
          parmsObj['mobile'] = "all"
          table.reload('demo',{
            url:'../api/api.php' + linxi.createUrlParse(parmsObj)
          })
        }


      })



      function getlayerVals(){

        var parmsObj={}
        parmsObj['type']='getKeFunFenPeiTable'
        parmsObj['starDate'] =$('#date1').val().split(' - ')[0]
        parmsObj['endDate'] = $('#date1').val().split(' - ')[1]
        parmsObj['status'] = $('#level').val()
        parmsObj['userId'] = $('#yunwei').val()==undefined?userId:$('#yunwei').val()
        if($('#mobileSearch').val().length==11){
          parmsObj['mobile'] = $('#mobileSearch').val()
        }else{
          parmsObj['mobile'] = 'all'
        }
        
        return parmsObj
      }

        



    })



	})
</script>
</html>